package com.wude.guild;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ListView;

import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.Utils;
import com.google.gson.Gson;
import com.mc.developmentkit.utils.ToastUtil;
import com.wude.bean.TaskBean;
import com.wude.bean.TrafficListBean;
import com.wude.guild.adapter.EverydayTaskAdapter;
import com.wude.guild.servercore.mints.TitleBaseActivity;
import com.wude.http.HttpCom;
import com.wude.http.HttpUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class EverydayTaskActivity extends TitleBaseActivity {
    private ListView lv_task;
    private EverydayTaskAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_everyday_task);

        setHeaderTitle("每日任务");
        lv_task = findViewById(R.id.lv_task);

        adapter = new EverydayTaskAdapter(this);
        lv_task.setAdapter(adapter);

//        List<TaskBean> beans = new ArrayList<>();
//        for (int i = 0; i < 5; i++) {
//            beans.add(new TaskBean());
//        }
//        adapter.setData(beans);
//        adapter.notifyDataSetChanged();

        Map<String, String> map = new HashMap<>();
        map.put("token", com.wude.tools.Utils.getLoginUser().token);
        HttpCom.POST(handler, HttpCom.getGetTask(), map, false);
    }

    /**
     * 获取任务列表
     */
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    List<TaskBean> beans = HttpUtils.DNSTaskList(msg.obj.toString());
                    adapter.setData(beans);
                    adapter.notifyDataSetChanged();
                    break;
                case 2:
                    ToastUtil.showToast("网络错误");
                    break;
            }
        }
    };
}
